/*
 * Copyright 2000-2011 Worth Enterprises, Inc.  All Rights Reserved.
 */
package com.worthent.foundation.util.state.provider;

import org.slf4j.Logger;

import com.worthent.foundation.util.state.StateErrorHandler;
import com.worthent.foundation.util.state.StateEvent;
import com.worthent.foundation.util.state.StateTable;
import com.worthent.foundation.util.state.TransitionActor;

/**
 * A simple implementation of the <code>StateErrorHandler</code> that simply
 * logs errors using the specified logger and severity level.
 * 
 * @author Erik K. Worth
 * @version $Id: LoggingStateErrorHandler.java 2 2011-11-28 00:10:06Z erik.k.worth@gmail.com $
 */
public class LoggingStateErrorHandler implements StateErrorHandler {

    /** The logger to use to log errors */
    private final Logger logger;

    public LoggingStateErrorHandler(final Logger logger) {
        this.logger = logger;
    }

    /** Logs the error */
    public void onError(
        final String fromState,
        final String toState,
        final StateTable table,
        final StateEvent event,
        final TransitionActor actor,
        final Exception cause) {

        final String actorName = actor.getName();
        logger.error("There was an error in state table, " +
            table.getStateTableName() +
            ", while in state, " +
            fromState +
            ", transitioning to state, " +
            toState +
            ", processing event, " +
            event.getName() +
            ", from the transition actor, " +
            actorName, cause);
    }
}
